package com.beiding.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TaskUtils {

    //任务分派线程池
    private static ScheduledExecutorService schedule = Executors.newScheduledThreadPool(1);

    //任务执行者
    private static ExecutorService executorService = Executors.newCachedThreadPool();

    public static void execute(Runnable task){
        executorService.submit(task);
    }
    public static void execute(Runnable task, long delay, TimeUnit timeUnit){
        schedule.schedule(()->{
            executorService.submit(task);
        }, delay, timeUnit);
    }
}
